import uuid
from typing import Any

import pytest
from recruit.domain.models.resume_education import (
    BaseResumeEducation,
    ResumeEducationCreate,
    ResumeEducationResult,
    ResumeEducationUpdate,
)

from .utils import check_attr_model, check_json_schema


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'year': 2010,
                'education_institution': 'Учебное заведение',
                'faculty': 'Факультет',
                'specialization': 'Специализация',
                'graduation_year': 2012
            },
            ('year', 'educationInstitution', 'faculty', 'specialization',
             'graduationYear')
    )]
)
def test_resume_education_base(
        data: dict[str, int | str],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(BaseResumeEducation, data)
    check_json_schema(BaseResumeEducation, keys)


@pytest.mark.parametrize(
    'data', [
        {},
        {'year': 2010,
         'graduation_year': 2009}
    ]
)
def test_validate_in_resume_education_base(
        data: dict[str, Any] | dict,
) -> None:
    with pytest.raises(ValueError):
        BaseResumeEducation(**data)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'year': 2010,
                'education_institution': 'Учебное заведение',
                'faculty': 'Факультет',
                'specialization': 'Специализация',
                'graduation_year': 2012
            },
            ('year', 'educationInstitution', 'faculty', 'specialization',
             'graduationYear')
    )]
)
def test_resume_education_create(
        data: dict[str, int | str],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeEducationCreate, data)
    check_json_schema(ResumeEducationCreate, keys)


@pytest.mark.parametrize(
    'data', [
        {},
        {'year': 2010,
         'graduation_year': 2009}
    ]
)
def test_validate_in_resume_education_create(
        data: dict[str, Any] | dict,
) -> None:
    with pytest.raises(ValueError):
        ResumeEducationCreate(**data)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'id': uuid.uuid4(),
                'year': 2010,
                'education_institution': 'Учебное заведение',
                'faculty': 'Факультет',
                'specialization': 'Специализация',
                'graduation_year': 2012
            },
            ('id', 'year', 'educationInstitution', 'faculty',
             'specialization', 'graduationYear')
    )]
)
def test_resume_education_result(
        data: dict[str, int | str],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeEducationResult, data)
    check_json_schema(ResumeEducationResult, keys)


@pytest.mark.parametrize(
    'data, keys', [(
            {
                'year': 2010,
                'education_institution': 'Учебное заведение',
                'faculty': 'Факультет',
                'specialization': 'Специализация',
                'graduation_year': 2012
            },
            ('year', 'educationInstitution', 'faculty', 'specialization',
             'graduationYear')
    )]
)
def test_resume_education_update(
        data: dict[str, int | str],
        keys: tuple[str, ...]
) -> None:
    check_attr_model(ResumeEducationUpdate, data)
    check_json_schema(ResumeEducationUpdate, keys)
    check_attr_model(ResumeEducationUpdate, {}, tuple(data))
    for key, value in data.items():
        check_attr_model(
            ResumeEducationUpdate,
            {key: value},
            tuple(k for k in data if k != key)
        )
    check_json_schema(ResumeEducationUpdate, keys)
